package com.hgkj.cloud.base.scheme.table;

import com.hgkj.cloud.base.scheme.ClsAnswerRequest;
import com.hgkj.cloud.base.scheme.ClsAnswerResult;
import com.hgkj.cloud.base.scheme.ClsScore;

import java.util.Map;

/**
 * 129: 创伤事件影响评定量表（Trauma）共15题
 */
public class Table129 implements TableCalculate{
    String code = "Trauma";

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public ClsAnswerResult calc(ClsAnswerRequest answer) {
        return GetTraumaFactorScore(answer);
    }

    @Override
    public String[] report(Map map) {
        return new String[0];
    }

    private static ClsAnswerResult GetTraumaFactorScore(ClsAnswerRequest answer) {
        // 总分
        ClsAnswerResult result = new ClsAnswerResult();
        result.setMessage("");
        result.setType(answer.getType());
        result.setUuid(answer.getUuid());
        try {
            // 1正确题数
            int MAX_NUM = 15;

            int intI;
            String[] strAnswer_c = answer.getAnswer().split(g_sChar);
            if (strAnswer_c.length > 1) {
                for (intI = 1; intI < strAnswer_c.length; intI++) {
                    strAnswer_c[intI] = strAnswer_c[intI].trim();
                }
            }

            String[] strClientAnswerA = strAnswer_c[0].toString().split(g_nChar);

            if (strClientAnswerA.length != MAX_NUM) {
                result.setMessage("答案数量不符！");
                return result;
            }

            int i;

            // 0,1,3,5
            int[] intScoreA = { 0, 1, 3, 5 };

            float vFactor = 0;

            // 总分
            // 原始代码
            // For i = 0 To strClientAnswerA.Length - 1
            for (i = 0; i < strClientAnswerA.length; i++) {
                vFactor += intScoreA[Integer.valueOf(strClientAnswerA[i]) - 1];
            }

            // 按原始分“诊断结果”
            // 按原始分“医生意见”
            int[] intValueA = { 8, 25, 43 };
            String[] strValueA = { "正常", "轻度", "中度", "重度" };
            String vAppraise = strValueA[strValueA.length - 1];
            String vDoctorIdea = "Trauma.1.4";
            for (i = 0; i < intValueA.length; i++) {
                if (vFactor <= intValueA[i]) {
                    vAppraise = strValueA[i];
                    vDoctorIdea = "Trauma.1." + String.valueOf(i + 1);
                    break;
                }
            }

            ClsScore.Trauma trauma = new ClsScore.Trauma();

            trauma.setTotal_o(vFactor);
            trauma.setTotal_a(vAppraise);
            trauma.setTotal_d(vDoctorIdea);

            result.setObject(trauma);
            return result;
        } catch (ArithmeticException e) {
            result.setMessage(e.toString());
            return result;
        }
    }

}
